package com.sjq.common.service.impl;


import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import net.sf.json.JSONObject;

import org.springframework.stereotype.Service;

import com.sjq.common.dao.LoginLogDao;
import com.sjq.common.entity.LoginLog;
import com.sjq.common.service.LoginLogService;
import com.sjq.common.util.Page;
@Service
public class LoginLogServiceImpl implements LoginLogService {
	
	@Resource
	private LoginLogDao lld;
	
	@Override
	public String selectPage(String pages,String xxzjbh, String yhm,String gajgjgdm, String dlsj_s,String dlsj_e, String ipdz) {
		
		// TODO Auto-generated method stub
		String dlsj_rqsj = "";
		
		if(dlsj_s!=null&&!"".equals(dlsj_s)&&dlsj_e!=null&&!"".equals(dlsj_e)){
			dlsj_rqsj = dlsj_s+"-"+dlsj_e;
		}
		//System.out.println(dlsj_rqsj);
		LoginLog tsd = new LoginLog();
		tsd.setDLSJ_RQSJ(dlsj_rqsj);
		tsd.setGAJGJGDM(gajgjgdm);
		tsd.setIPDZ(ipdz);
		tsd.setXXZJBH(xxzjbh);
		tsd.setYHM(yhm);
		
		List<LoginLog> list = lld.selectAll(tsd);
		int count = list.size();
		int pageNum = Integer.parseInt(pages);
		Page page = new Page(pageNum, count);
		
		List<LoginLog> pageList = lld.selectPage(page.getStart(),page.getEnd(), tsd);
		Map map = new HashMap();
		map.put("page", page);
		map.put("datas", pageList);
		String json=JSONObject.fromObject(map).toString();
		return json;
	}

	@Override
	public Map<String,String> insertLoginLog(LoginLog tsd) {
		//用于返回结果的map
		Map<String,String> map = new HashMap<String, String>();
		
		//将登录信息传至LoginLogDao的insert方法
		int i = lld.insert(tsd);
		
		//返回int值判断结果
		if(i==1){//成功
			map.put("result", "success");
			map.put("msg", "存入日志成功!");
			return map;
		}else{//失败
			map.put("result", "error");
			map.put("msg", "存入日志失败!");
			return map;
			
		}
	}

}
